package metrics

import (
	"github.com/prometheus/client_golang/prometheus"
)

const (
	PhaseDurationSeconds            = "phase_duration_seconds"
	ClusterUnhealthyCount           = "cluster_unhealthy_count"
	ClusterReadyStatus              = "cluster_ready_status"
	ClusterBootstrapDurationSeconds = "cluster_bootstrap_duration_seconds"
	NodeBootstrapDurationSeconds    = "node_bootstrap_duration_seconds"
	NodeBootstrapFailedCount        = "node_bootstrap_failed_count"
	NodeBootstrapSuccessCount       = "node_bootstrap_success_count"

	AddonInstallDurationSeconds = "addon_install_duration_seconds"
	AddonInstallFailedCount     = "addon_install_failed_count"
	AddonInstallSuccessCount    = "addon_install_success_count"
	AddonInstallCount           = "addon_install_count"
)

var (
	PhaseDurationVec = func(clusterKey string) (string, prometheus.Collector) {
		return PhaseDurationSeconds, prometheus.NewGaugeVec(
			newGaugeOpts(PhaseDurationSeconds, clusterKey),
			[]string{"phase", "start_time", "end_time", "describe"},
		)
	}

	//ClusterLatestReadyDurationVec = prometheus.NewGaugeVec(
	//	newGaugeOpts("cluster_latest_ready_duration_seconds"),
	//	[]string{"bke_cluster", "start_time", "end_time"},
	//)

	ClusterUnhealthyCountVec = func(clusterKey string) (string, prometheus.Collector) {
		return ClusterUnhealthyCount, prometheus.NewCounterVec(
			newCounterOpts(ClusterUnhealthyCount, clusterKey),
			nil,
		)
	}

	ClusterReadyStatusVec = func(clusterKey string) (string, prometheus.Collector) {
		return ClusterReadyStatus, prometheus.NewGaugeVec(
			newGaugeOpts(ClusterReadyStatus, clusterKey),
			nil,
		)
	}

	ClusterBootstrapDurationVec = func(clusterKey string) (string, prometheus.Collector) {
		return ClusterBootstrapDurationSeconds, prometheus.NewGaugeVec(
			newGaugeOpts(ClusterBootstrapDurationSeconds, clusterKey),
			[]string{"start_time", "end_time"},
		)
	}

	//MasterNodesBootstrapDurationVec = prometheus.NewGaugeVec(
	//	newGaugeOpts("master_nodes_bootstrap_duration_seconds_total"),
	//	[]string{"bke_cluster"},
	//)

	//MasterNodeInitDurationVec = prometheus.NewGaugeVec(
	//	newGaugeOpts("master_node_init_duration_seconds"),
	//	[]string{"bke_cluster", "node", "start_time", "end_time"},
	//)

	//MasterNodeJoinDurationVec = prometheus.NewGaugeVec(
	//	newGaugeOpts("master_node_join_duration_seconds"),
	//	[]string{"bke_cluster", "node", "start_time", "end_time"},
	//)

	//WorkerNodesBootstrapDurationTotalVec = prometheus.NewGaugeVec(
	//	newGaugeOpts("worker_nodes_bootstrap_duration_seconds_total"),
	//	[]string{"bke_cluster"},
	//)

	NodeBootstrapDurationVec = func(clusterKey string) (string, prometheus.Collector) {
		return NodeBootstrapDurationSeconds, prometheus.NewGaugeVec(
			newGaugeOpts(NodeBootstrapDurationSeconds, clusterKey),
			[]string{"node", "role", "boot_success", "start_time", "end_time"},
		)
	}

	NodeBootstrapFailedCountVec = func(clusterKey string) (string, prometheus.Collector) {
		return NodeBootstrapFailedCount, prometheus.NewCounterVec(
			newCounterOpts(NodeBootstrapFailedCount, clusterKey),
			nil,
		)
	}

	NodeBootstrapSuccessCountVec = func(clusterKey string) (string, prometheus.Collector) {
		return NodeBootstrapSuccessCount, prometheus.NewCounterVec(
			newCounterOpts(NodeBootstrapSuccessCount, clusterKey),
			nil,
		)
	}

	AddonInstallDurationVec = func(clusterKey string) (string, prometheus.Collector) {
		return AddonInstallDurationSeconds, prometheus.NewGaugeVec(
			newGaugeOpts(AddonInstallDurationSeconds, clusterKey),
			[]string{"addon", "start_time", "end_time"},
		)
	}

	AddonInstallFailedCountVec = func(clusterKey string) (string, prometheus.Collector) {
		return AddonInstallFailedCount, prometheus.NewCounterVec(
			newCounterOpts(AddonInstallFailedCount, clusterKey),
			nil,
		)
	}

	AddonInstallSuccessCountVec = func(clusterKey string) (string, prometheus.Collector) {
		return AddonInstallSuccessCount, prometheus.NewCounterVec(
			newCounterOpts(AddonInstallSuccessCount, clusterKey),
			nil,
		)
	}

	AddonInstallCountVec = func(clusterKey string) (string, prometheus.Collector) {
		return AddonInstallCount, prometheus.NewCounterVec(
			newCounterOpts(AddonInstallCount, clusterKey),
			nil,
		)
	}
)

func RegisterBkeVec(collector Collector) {
	collector.RegisterVec(
		PhaseDurationVec,
		//ClusterLatestReadyDurationVec,
		ClusterUnhealthyCountVec,
		ClusterReadyStatusVec,
		ClusterBootstrapDurationVec,
		//MasterNodesBootstrapDurationVec,
		//MasterNodeInitDurationVec,
		//MasterNodeJoinDurationVec,
		//WorkerNodesBootstrapDurationTotalVec,
		NodeBootstrapDurationVec,
		NodeBootstrapFailedCountVec,
		NodeBootstrapSuccessCountVec,
		AddonInstallDurationVec,
		AddonInstallFailedCountVec,
		AddonInstallSuccessCountVec,
		AddonInstallCountVec,
	)
}
